//
//  ZCRaiseVC.m
//  zctx
//
//  Created by 郭亚京 on 15/10/9.
//  Copyright © 2015年 sanliang. All rights reserved.
//
#import "DZWebViewController.h"
#import "ZCRaiseVC.h"
#import "ZCRaiseCell.h"
#import "ZCMechanismListVC.h"
#import "ZCItemListVC.h"
#import "ZCRaisePayVC.h"
#import "ZCRaiseadressCel.h"
#import "ZCRaisePicCell.h"

#import "ZCClassificationVC.h"  //分类
#import "SDItemButton.h"
#import "ELCImagePickerController.h"
#import <AssetsLibrary/AssetsLibrary.h>

#import "ZCScanVC.h" //扫一扫
#import "FSMediaPicker.h"

typedef enum {
    RaiseReginTypeProvince = 100,
    RaiseReginTypeCity,
} RaiseReginType;

@interface ZCRaiseVC ()<UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate,UITextViewDelegate,UITextFieldDelegate,ZCRaiseCellDelegate,MessagePhotoViewDelegate,FSMediaPickerDelegate>{
    NSInteger imageCount;
    NSMutableArray *mainArray;
    NSInteger maxNum;
    NSMutableArray *ImgArray;
    BOOL isshow;
    UIImageView *rightView;
}

@property (nonatomic, assign) NSInteger tableViewNum;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *viewFooter;


@property (nonatomic, strong) NSString *strMechanismid;       //检测机构id
@property (nonatomic, strong) NSString *strItemid;            //检测项目id
@property (nonatomic, strong) NSString *citycode;           //城市代码
@property (nonatomic,strong)NSMutableDictionary *contentDict;
@property (nonatomic,strong)NSMutableArray *imgContentArray;   //上传图片返回结果数组

@property (nonatomic,strong)NSMutableArray *contentArray; //检测内容
@end

@implementation ZCRaiseVC


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"ZCRaiseVC"];
    [MTA trackPageViewBegin:@"ZCRaiseVC"];
    self.tabBarController.hidesBottomBarWhenPushed = YES;
    self.navigationController.navigationBarHidden = NO;
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"ZCRaiseVC"];
    [MTA trackPageViewEnd:@"ZCRaiseVC"];
    self.tabBarController.hidesBottomBarWhenPushed = NO;
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"delegate" object:nil];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.tableView.shiftHeightAsDodgeViewForMLInputDodger = 44.0f+5.0f;
    [self.tableView registerAsDodgeViewForMLInputDodger];
}

-(void)viewDidLayoutSubviews {
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
        
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.contentDict = [NSMutableDictionary dictionaryWithCapacity:0];
    self.imgContentArray =[NSMutableArray array];
    self.contentArray = [NSMutableArray array];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(delegateButton:)
                                                 name:@"delegate" object:nil];
    isshow = NO;
    self.tableViewNum = 4;
    maxNum = 3;
    imageCount = 0;
    mainArray = [[NSMutableArray alloc]init];
    ImgArray = [[NSMutableArray alloc]init];
    
    if (self.pushpjName) {
         [self.contentDict setValue:self.pushpjName forKey:@"1"];
    }

    [self.contentDict setValue:@"其他" forKey:@"classficationname"];
    [self.contentDict setValue:@"129" forKey:@"classVCid"];
    [self.contentDict setValue:@"常规理化" forKey:@"itemname"];
    [self.contentDict setValue:@"500" forKey:@"money"];
    self.strItemid = @"28";
    [self.contentDict setValue:@"PONY谱尼测试集团" forKey:@"mechanismname"];
    self.strMechanismid = @"21";
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSIndexPath *indexPach = [NSIndexPath indexPathForRow:4 inSection:0];
       [self requeststarcategoryid:@"129" andwith:indexPach andbool:NO];
    });
    
    [self setNavigationItems];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#ebeded"];
    self.navigationItem.title = @"发起检测";
    
    //添加tableview
    [self.view addSubview:self.tableView];
    
    self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0, 0,0));
    }];
    [self.tableView registerNib:[UINib nibWithNibName:@"ZCRaiseadressCel" bundle:nil] forCellReuseIdentifier:@"addressCell"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ClickScanInput:) name:@"scanInput" object:nil];
}

- (void)ClickScanInput:(NSNotification *)text{
    
    NSLog(@"%@",text.userInfo[@"title"]);
    NSString *name =[NSString stringWithFormat:@"%@",text.userInfo[@"title"]];
    [self.contentDict setValue:name forKey:@"1"];
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
    [self reloadTableViewCell:[NSArray arrayWithObject:indexPath]];
 
}

-(void)delegateButton:(NSNotification *)nofi{
    NSIndexPath *index = [NSIndexPath indexPathForItem:5 inSection:0];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone];
}

#pragma mark - request


#pragma mark 提交

- (void)requestSubmit {
    [self.imgContentArray removeAllObjects];
    NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0];
    NSIndexPath *indextwo = [NSIndexPath indexPathForRow:2 inSection:0];
    ZCRaiseCell *cellone = [self.tableView cellForRowAtIndexPath:index];
    ZCRaiseCell *celltwo = [self.tableView cellForRowAtIndexPath:indextwo];
    [cellone.textField resignFirstResponder];
    [celltwo.textView resignFirstResponder];
    
    NSString *pdname = [NSString stringWithFormat:@"%@",self.contentDict[@"1"]];//产品名称
    NSString *content = [NSString stringWithFormat:@"%@",self.contentDict[@"2"]];//众测故事
    
    if ([NSString isNull:content]) {
        content = @"食品安全我做主，小伙伴们快来支持我~，一起来参与食品安全检测...";
    }
    
    
    NSString *itemnameid =  [self.contentDict objectForKey:@"classVCid"];//检测项目id
    NSString *money =[NSString stringWithFormat:@"%@",[self.contentDict objectForKey:@"money"]];//检测金额
    NSScanner *scanner = [NSScanner scannerWithString:money];
    [scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
    int number;
    [scanner scanInt:&number];
    money = [NSString stringWithFormat:@"%d",number*100];
    
    if ([NSString isNull:pdname] ==YES) {
        NSLog(@"pdname = %@",pdname);
        [[[iToast makeText:@"请填写产品名称"]setGravity:iToastGravityCenter] show];
        return;
    }
    NSLog(@"pdname = %ld,pjname = %@",pdname.length,content);
    
    [GMDCircleLoader setOnView:self.view withTitle:@"努力加载中..." animated:YES];
    if (ImgArray.count>0) {
        [NetworkManager requestFoundingPublishimageuploadMid:UserModel.mid password:UserModel.password image:ImgArray success:^(NSData *data) {
            
            NSLog(@"task33");
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
            NSString *str = [NSString stringWithFormat:@"%@",[dic objectForKey:@"content"]];
            [self.imgContentArray addObject:str];
            NSLog(@"上传图片，返回字典 = %@ ,array = %@",dic,self.imgContentArray);
            
            if (self.imgContentArray.count == ImgArray.count) {
                NSString *sampleidStr = [self.imgContentArray componentsJoinedByString:@","];
                [NetworkManager requestFoundingPublishWithMid:UserModel.mid
                                                     password:UserModel.password
                                                       pjname:pdname
                                                       pdname:pdname
                                                     citycode:@"4403"
                                                        brand:@""
                                                    packageid:self.strItemid
                                                institutionid:self.strMechanismid
                                                       emoney:money
                                                     fromtype:@"2"
                                                      content:content
                                                   categoryid:itemnameid
                                                     sampleid:sampleidStr  success:^(NSDictionary *dictResponse) {
                                                         
                                                         [GMDCircleLoader hideFromView:self.view animated:YES];
                                                         NSString *errStr = [NSString stringWithFormat:@"%@",[dictResponse objectForKey:@"err"]];
                                                         
                                                         if ([errStr isEqualToString:@"0"]) {
                                                             ZCRaisePayVC *payvc = [[ZCRaisePayVC alloc]init];
                                                             payvc.markStr = @"1";
                                                             payvc.pid = [NSString stringWithFormat:@"%@",[dictResponse objectForKey:@"content"]];
                                                             payvc.pjname =[NSString stringWithFormat:@"%@检测", pdname];
                                                             payvc.pjusername = UserModel.username;
                                                             [self.navigationController pushViewController:payvc animated:YES];
                                                         }
                                                     } failure:^(NSError *error) {
                                                         
                                                     }];
            }else{
                NSLog(@"上传图片，返回字典 = %ld ,array = %ld",ImgArray.count,self.imgContentArray.count);
            }
        } failure:^(NSError *error) {
            [GMDCircleLoader hideFromView:self.view animated:YES];
        }];
    }else{
        [NetworkManager requestFoundingPublishWithMid:UserModel.mid
                                             password:UserModel.password
                                               pjname:pdname
                                               pdname:pdname
                                             citycode:@"4403"
                                                brand:@""
                                            packageid:self.strItemid
                                        institutionid:self.strMechanismid
                                               emoney:money
                                             fromtype:@"2"
                                              content:content
                                           categoryid:itemnameid
                                             sampleid:@""  success:^(NSDictionary *dictResponse) {
                                                 [GMDCircleLoader hideFromView:self.view animated:YES];
                                                 NSString *errStr = [NSString stringWithFormat:@"%@",[dictResponse objectForKey:@"err"]];
                                                 
                                                 if ([errStr isEqualToString:@"0"]) {
                                                     ZCRaisePayVC *payvc = [[ZCRaisePayVC alloc]init];
                                                     payvc.markStr = @"1";
                                                     payvc.pid = [NSString stringWithFormat:@"%@",[dictResponse objectForKey:@"content"]];
                                                     payvc.pjname =[NSString stringWithFormat:@"%@检测", pdname];
                                                     payvc.pjusername = UserModel.username;
                                                     [self.navigationController pushViewController:payvc animated:YES];
                                                 }
                                             } failure:^(NSError *error) {
                                                 [GMDCircleLoader hideFromView:self.view animated:YES];
                                             }];
    }
        NSLog(@"未传图片");
}

#pragma mark - button

-(void)setNavigationItems {
    
    UIButton * leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(0, 0, 19, 36);
    [leftButton setImage:[UIImage imageNamed:@"navigation_back"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * barButtonItem_leftNavBar = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem = barButtonItem_leftNavBar;
}

- (void)backButtonPressed{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)tapGestureRecognizer {
    [self.view endEditing:YES];
}

- (void)submitButtonClick {
    [self requestSubmit];
}

#pragma mark - UITableView DataSource & Delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.tableViewNum;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIndentity = @"Cell";
    ZCRaiseCell *cell;

    if (indexPath.row==0) {
        ZCRaisePicCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (cell ==nil) {
            cell = [[ZCRaisePicCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        }
        cell.delegate = self;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.PicArray  = ImgArray;
        return cell;
    }else if (indexPath.row == 1) {
        cell = [[ZCRaiseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentity cellType:RaiseCellTypeSao];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textField.delegate =self;
        [cell.labelTitle setText:@"产品名称："];
        [cell.textField setPlaceholder:@"填写产品名称,详细点哦~"];
        cell.textField.tag = 1;
        if (self.contentDict[@"1"]) {
            cell.textField.text = self.contentDict[@"1"];
        }
        [cell.saoButton addTarget:self action:@selector(saoButtonClick) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    } else if(indexPath.row ==2){
        //备注信息
        cell = [[ZCRaiseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentity cellType:RaiseCellTypeText];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.labelTitle.text=@"众测故事：";
        cell.textView.delegate = self;
        cell.textView.tag = 2;
        if (self.contentDict[@"2"]) {
            cell.textView.text = self.contentDict[@"2"];
        }
        return cell;
    }else if (indexPath.row==3){
        cell = [[ZCRaiseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentity cellType:RaiseCellTypemore];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.indexPath = indexPath;
        cell.delegate = self;
        return cell;
    }else if(indexPath.row<8)
        {
        cell = [[ZCRaiseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentity cellType:RaiseCellTypePush];
        cell.indexPath = indexPath;
        NSString *itemname =[self.contentDict objectForKey:@"itemname"];
        NSString *mechanismname =[self.contentDict objectForKey:@"mechanismname"];
        NSString *money =[self.contentDict objectForKey:@"money"];
        
        if (indexPath.row==4) {
            NSString *classname =[self.contentDict objectForKey:@"classficationname"];
            if (classname) {
                [cell.labelInfo setText:classname];
            }else{
                [cell.labelInfo setText:@"选择产品分类"];
            }
        }else if (indexPath.row == 5) {
            //检测机构
            if (itemname) {
                [cell.labelInfo setText:itemname];
            }
        } else if(indexPath.row==6){
            //检测项目
            if (mechanismname) {
                [cell.labelInfo setText:mechanismname];
            }
        }else if(indexPath.row ==7){
            cell.rightImgView.hidden = YES;
            if (money) {
                cell.labelInfo.textColor = [UIColor colorWithHexString:@"#e94f4e"];
                [cell.labelInfo setText:[NSString stringWithFormat:@"%@",money]];
            }
        }
    }else{
        cell = [[ZCRaiseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentity cellType:RaiseCellTypePrompt];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor colorWithHexString:@"#e7f9f9"];
    }   return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row==0) {
        return 106;
    }else if (indexPath.row==1){
        return 44;
    }else if(indexPath.row==2){
        return 70;
    }else{
        return 44;
    }
}

-(void)didSeclectButtonClick:(NSIndexPath *)index{
    double degree;
    if (isshow) {
        isshow = NO;
        self.tableViewNum = 4;
        degree = 0;
    }else{
        isshow = YES;
        self.tableViewNum = 9;
        degree = M_PI;
    }
    [self.tableView reloadData];
    ZCRaiseCell *cell = (ZCRaiseCell*)[self.tableView cellForRowAtIndexPath:index];
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
        cell.rightImgView.layer.transform = CATransform3DMakeRotation(degree, 0, 0, 1);
    } completion:NULL];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row==3) {
        
    }
    __block  ZCRaiseVC *weekself = self;
    if (indexPath.row==4) {
        ZCClassificationVC *classVC = [[ZCClassificationVC alloc]init];
        classVC.hidesBottomBarWhenPushed = YES;
        [weekself.navigationController pushViewController:classVC animated:YES];
        classVC.cellselectClassification = ^(NSString *title,NSString *contentid){
            [weekself.contentDict setValue:title forKey:@"classficationname"];
            [weekself.contentDict setValue:contentid forKey:@"classVCid"];
            NSLog(@"classficationname = %@",title);
            NSLog(@"contentid = %@",contentid);
            [weekself requeststarcategoryid:contentid andwith:indexPath andbool:YES];
        };
    }
    if(indexPath.row == 5) {
        NSString *starcategoryid =  [self.contentDict objectForKey:@"classVCid"];
            //检测项目
        NSLog(@"sortid = %@",starcategoryid);
            ZCItemListVC *vc = [[ZCItemListVC alloc] init];
            vc.sortid =starcategoryid;
            vc.dataArray = self.contentArray;
            vc.cellselectItemList = ^(NSString *ids,NSString *name,NSString * money){
                [self.contentDict setValue:name forKey:@"itemname"];
                [self.contentDict setValue:money forKey:@"money"];
                weekself.strItemid = ids;
                NSLog(@"meny = %@",money);
                NSIndexPath *indexmoney = [NSIndexPath indexPathForRow:7 inSection:0];
                [weekself reloadTableViewCell:[NSArray arrayWithObjects:indexPath,indexmoney,nil]];
            };
            [self.navigationController pushViewController:vc animated:YES];
    }
    if (indexPath.row==6) {
        //检测机构
        ZCMechanismListVC *vc = [[ZCMechanismListVC alloc] init];
        vc.cellselectMechanismList = ^(NSString *ids,NSString *name){
            [self.contentDict setValue:name forKey:@"mechanismname"];
            weekself.strMechanismid = ids;
            NSLog(@"检测机构 = %@ ,name =%@",ids,name);
            [self reloadTableViewCell:[NSArray arrayWithObject:indexPath]];
        };
        [self.navigationController pushViewController:vc animated:YES];
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0001;
}


-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

#pragma mark 根据分类id 获取项目内容
-(void)requeststarcategoryid:(NSString *)contentid andwith:(NSIndexPath *)index andbool:(BOOL)isbegin{
    
    NSMutableArray *titleArray = [NSMutableArray array];
    NSMutableArray *idArray = [NSMutableArray array];
    
    [NetworkManager requestFoundingGetPackagesWithSortid:contentid success:^(NSMutableArray *array) {
        ProgressDismiss;
        NSLog(@"array = %@",array);
        if (array.count>0) {
            self.contentArray = [array copy];
            NSInteger muchMoney = 0;
            for (ZCItemModelContent *model in self.contentArray) {
                if (model.ischecked==1) {
                    NSInteger money = [[NSString stringWithFormat:@"%@",model.price] integerValue];
                    muchMoney += money;
                    NSString * name =[NSString stringWithFormat:@"%@",model.name];
                    NSString * contentIdentifier =[NSString stringWithFormat:@"%@",model.contentIdentifier];
                    [titleArray addObject:name];
                    [idArray addObject:contentIdentifier];
                }
            }
            NSString *pid = [idArray componentsJoinedByString:@","];
            NSString *pname = [titleArray componentsJoinedByString:@","];
            NSString *price = [NSString stringWithFormat:@"%ld",muchMoney/100];
            self.strItemid = pid;
            [self.contentDict setValue:pname forKey:@"itemname"];
            [self.contentDict setValue:price forKey:@"money"];
            
            
            NSLog(@"pname = %@, price = %@ , pid= %@",pname,price, pid);
          NSIndexPath *pjnameindex = [NSIndexPath indexPathForRow:5 inSection:0];
          NSIndexPath *pjmoneyindex = [NSIndexPath indexPathForRow:7 inSection:0];
            
            if (isbegin == YES) {
                [self reloadTableViewCell:[NSArray arrayWithObjects:index,pjnameindex,pjmoneyindex, nil]];
            }else{
                
            }
        
        }
    } failure:^(NSError *error) {
        ProgressDismiss;
    }];
}

-(void)reloadTableViewCell:(NSArray *)array{
    [self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationNone];
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    
    NSString *tag = [NSString stringWithFormat:@"%ld",textField.tag];
    if (!textField.text) {
        textField.text = @"";
    }
    [self.contentDict setValue:textField.text forKey:tag];
}

-(void)textViewDidEndEditing:(UITextView *)textView{
    NSString *tag = [NSString stringWithFormat:@"%ld",textView.tag];
    if (!textView.text) {
        textView.text = @"";
    }
    NSLog(@"sdfa");
    [self.contentDict setValue:textView.text forKey:tag];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

#pragma mark 扫条码
-(void)saoButtonClick{
    ZCScanVC *vc= [[ZCScanVC alloc]init];
    vc.israise = @"raise";
    vc.ScanResultWithName = ^(NSString *title){
        [self.contentDict setValue:title forKey:@"1"];
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
        [self reloadTableViewCell:[NSArray arrayWithObject:indexPath]];
    };
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}


-(void)TextFiledresignFirstResponder{
    NSIndexPath *pjindex = [NSIndexPath indexPathForRow:0 inSection:0];
    NSIndexPath *pdindex = [NSIndexPath indexPathForRow:1 inSection:0];
    ZCRaiseCell *pjcell =(ZCRaiseCell*)[self.tableView cellForRowAtIndexPath:pjindex]; //项目名
    ZCRaiseCell *pdcell =(ZCRaiseCell*)[self.tableView cellForRowAtIndexPath:pdindex];  //品牌名
    [pjcell.textField resignFirstResponder];
    [pdcell.textField resignFirstResponder];
}

#pragma mark - UIGestureRecognizerDelegate Methods

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if ([touch.view isKindOfClass:[UITableViewCell class]]) {
        return NO;
    } else {
        return YES;
    }
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark  MessagePhotoViewDelegate

- (void)didSelectePhotoMenuItem:(NSArray *)picArray atIndex:(NSInteger)index{
    ImgArray = [picArray mutableCopy];
    imageCount = ImgArray.count;
    FSMediaPicker *mediaPicker = [[FSMediaPicker alloc] init];
    mediaPicker.delegate = self;
    
    if (DEVICE_SYSTEM_VERSION) {
        [mediaPicker showFromView:self.view];
    }else{
        [mediaPicker showActionSheet:self.view];
    }
}

- (void)mediaPicker:(FSMediaPicker *)mediaPicker didFinishWithMediaInfo:(NSDictionary *)mediaInfo
{
    NSLog(@"img = %@",mediaInfo.editedImage);
    [ImgArray addObject:mediaInfo.editedImage];
    NSIndexPath *index = [NSIndexPath indexPathForItem:0 inSection:0];
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationNone];
    
}

#pragma mark - instance

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = self.viewFooter;
        _tableView.sectionFooterHeight = 0.0001;
        _tableView.backgroundColor = [UIColor colorWithHexString:@"#fafcfb"];
        _tableView.separatorColor = RGB(236, 237, 238);
    }
    return _tableView;
}

- (UIView *)viewFooter {
    if (!_viewFooter) {
        _viewFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
        
        UIButton *userbutton = [UIButton buttonWithType:UIButtonTypeCustom];
        [userbutton setFrame:CGRectMake(50, 24, SCREEN_WIDTH-100, 20)];
        userbutton.titleLabel.font = [UIFont systemFontOfSize:13];
        [userbutton setTitleColor:[UIColor colorWithHexString:@"#03ab9e"] forState:UIControlStateNormal];
        [userbutton setTitle:@"《众测天下用户服务协议》" forState:UIControlStateNormal];
        [userbutton addTarget:self action:@selector(userButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.viewFooter addSubview:userbutton];
        
        //提交
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.layer.cornerRadius = 5;
        [button setFrame:CGRectMake(20, 60, SCREEN_WIDTH-40, 40)];
        button.backgroundColor =[ UIColor colorWithHexString:@"#03ab9e"];
        [button setTitle:@"同意协议并发起" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(submitButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.viewFooter addSubview:button];
    }
    return _viewFooter;
}

-(void)userButtonClick{
    
    DZWebViewController *vc = [[DZWebViewController alloc] init];
    vc.strURL = [NSString stringWithFormat:@"%@%@",[NetworkManager strURLBasic],@"/index.php/M/Index/agreement"];
    vc.title = @"用户服务协议";
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}


@end
